package com.nbufe.observer.demo2;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author Zan
 * @Create 2024/5/29 14:03
 * @ClassName: WeatherData
 * @Description : TODO 请用一句话描述该类的功能
 */
public class WeatherData implements Subject {

    private List<Observer> list = new ArrayList<>();

    private String time;
    private double temperature;
    private double humidity;
    private int windSpeed;
    private int AQLevel;

    public WeatherData(String time, double temperature, double humidity, int windSpeed, int AQLevel) {
        this.time = time;
        this.temperature = temperature;
        this.humidity = humidity;
        this.windSpeed = windSpeed;
        this.AQLevel = AQLevel;
    }

    @Override
    public void addObserver(Observer o) {
        list.add(o);
    }

    @Override
    public void delObserver(Observer o) {
        list.remove(o);
    }

    @Override
    public void notifyMsg() {
        System.out.println("推送天气消息");
        // 先对天气进行组装
        String msg = "当前时间：" + time + "\t温度：" + temperature + "°\t湿度：" +
                humidity + "°\t风力：" + windSpeed + "级\t空气质量等级:" + AQLevel + "级";
        for (Observer observer : list) {
            // 进行推送
            observer.getMessage(msg);
        }
    }
}
